<template>
    <el-form :model="form" :rules="rules" ref="modifyAttendanceForm">
      <el-form-item label="考勤记录ID" prop="id">
        <el-input v-model="form.id" disabled></el-input>
      </el-form-item>
      <el-form-item label="用户名" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="真实姓名" prop="realName">
        <el-input v-model="form.realName"></el-input>
      </el-form-item>
      <el-form-item label="请假开始时间" prop="startTime">
        <el-date-picker
          v-model="form.startTime"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="请假结束时间" prop="endTime">
        <el-date-picker
          v-model="form.endTime"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="请假原因" prop="reason">
        <el-input type="textarea" v-model="form.reason"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('modifyAttendanceForm')">提交</el-button>
        <el-button @click="resetForm('modifyAttendanceForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </template>
  
  <script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { ElMessage } from 'element-plus';
  import axios from 'axios';
 
  
  const form = reactive({
    id: '',
    username: '',
    realName: '',
    startTime: '',
    endTime: '',
    reason: ''
  });
  
  const rules = {
    // 添加验证规则
  };
  
  const modifyAttendanceForm = ref(null);
  
  const submitForm = (formName) => {
    modifyAttendanceForm.value.validate((valid) => {
      if (valid) {
        // 修改考勤记录的逻辑
        console.log('提交修改的考勤记录:', form);
        // 在这里添加将修改后的考勤记录提交到后端的逻辑
        // 例如，使用axios发起POST请求
        // axios.post('/api/attendance/modify', form)
        //   .then(response => {
        //     // 处理响应
        //     ElMessage.success('考勤记录修改成功！');
        //     // 重置表单
        //     resetForm(formName);
        //   })
        //   .catch(error => {
        //     // 处理错误
        //     console.error('Error modifying attendance:', error);
        //     ElMessage.error('考勤记录修改失败！');
        //   });
      } else {
        console.log('error submit!!');
        return false;
      }
    });
  };
  
  const resetForm = (formName) => {
    modifyAttendanceForm.value.resetFields();
  };
  </script>
  
  <style>
  /* 自定义样式 */
  .attendance-form {
    margin-top: 20px;
  }
  </style>
  